line-bot-sdk-python icon indicating copy to clipboard operation
line-bot-sdk-python copied to clipboard

Update FileMessage Attribute name to match

Open ninyawee opened this issue 5 years ago • 9 comments

Problem

what __repr__ show Screenshot 2020-03-25 at 11 19 43 PM

what I expect

event.message["fileName"] # or
event.message.fileName

but this is what to code

event.message.file_name

for fileSize as well

ninyawee avatar Mar 25 '20 16:03 ninyawee

Do you suggest __repr__ implementation should be modified so that it prints like this?

message: { file_name: ..., file_size: ..., ... }

okue avatar Mar 26 '20 01:03 okue

yes

ninyawee avatar Mar 26 '20 08:03 ninyawee

Thanks for opening the nice issue.

okue avatar Mar 26 '20 08:03 okue

Hello @CircleOnCircles, The pull request may meet your request.

o926428377 avatar Apr 05 '20 04:04 o926428377

Hello @CircleOnCircles, The pull request may meet your request.

Already check that so the PR allow dictionary-access e.g. message['fileName'] Gj 👍

There are 2 more things to consider.

  1. __repr__ now matched with dictionary-access which is a nice thing 👍
  2. the dot access e.g. message.file_name is it consider an internal api?

if it is, may be leave it as is or refactor the variable name to message._file_name to signal developers and IDE to not suggest that variable.

else we might need another PR to

  1. refactor the name to message.fileName OR
  2. do a monkey patch or @property for message.fileName

ninyawee avatar Apr 05 '20 05:04 ninyawee

Hello @CircleOnCircles, The pull request may meet your request.

Already check that so the PR allow dictionary-access e.g. message['fileName'] Gj 👍

There are 2 more things to consider.

  1. __repr__ now matched with dictionary-access which is a nice thing 👍
  2. the dot access e.g. message.file_name is it consider an internal api?

There is a good question, it could be answered by official Line developer. I thought it might consider the beautiful Python code.

if it is, may be leave it as is or refactor the variable name to message._file_name to signal developers and IDE to not suggest that variable.

else we might need another PR to

  1. refactor the name to message.fileName OR
  2. do a monkey patch or @property for message.fileName

I have the idea that making a switched variable to decide attribute name format (fileName or file_name) in Message class.

o926428377 avatar Apr 05 '20 08:04 o926428377

What is a 'switch var' in python like? I've never heard this before.

ninyawee avatar Apr 05 '20 15:04 ninyawee

What is a 'switch var' in python like? I've never heard this before.

Oh sorry, it just named by myself. It's mean a variable which could choose whether using the original attribute name. btw, I've committed it to https://github.com/line/line-bot-sdk-python/pull/252

o926428377 avatar Apr 05 '20 16:04 o926428377

Oh sorry, it just named by myself. It's mean a variable which could choose whether using the original attribute name. btw, I've committed it to #252

oh I see what you mean. 😉

ninyawee avatar Apr 05 '20 16:04 ninyawee

resolved by https://github.com/line/line-bot-sdk-python/pull/252

Yang-33 avatar Jul 05 '23 23:07 Yang-33