Skip to content

"FileHandler" has no attribute "set_name" #5257

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
spagh-eddie opened this issue Apr 26, 2021 · 6 comments
Closed

"FileHandler" has no attribute "set_name" #5257

spagh-eddie opened this issue Apr 26, 2021 · 6 comments

Comments

@spagh-eddie
Copy link
Contributor

Bug Report

I have looked in the logging standard library and to me it seems that FileHandler has a standard mro, inheriting set_name from Handler, yet mypy complains:

To Reproduce

# example.py
from logging import FileHandler

h = FileHandler('a')
h.set_name('b')
$ mypy example.py 
example.py:4: error: "FileHandler" has no attribute "set_name"
Found 1 error in 1 file (checked 1 source file)

Expected Behavior

No error

Your Environment

$ mypy --version
mypy 0.770
$ python --version
Python 3.7.5

No configuration files, flags, etc.

@hauntsaninja hauntsaninja transferred this issue from python/mypy Apr 26, 2021
@hauntsaninja
Copy link
Collaborator

Looks like there are several improvements to be made to logging:

λ stubtest logging --concise --custom-typeshed-dir .
logging.BufferingFormatter is not present in stub
logging.Formatter.usesTime is not present in stub
logging.Handler.get_name is not present in stub
logging.Handler.set_name is not present in stub
logging.Logger.callHandlers is not present in stub
logging.Logger.fatal is not present in stub
logging.LoggerAdapter.manager is not present in stub
logging.LoggerAdapter.name is not present in stub
logging.PercentStyle.validate is not present in stub
logging.PercentStyle.validation_pattern is not present in stub
logging.StrFormatStyle.field_spec is not present in stub
logging.StrFormatStyle.fmt_spec is not present in stub
logging.StrFormatStyle.validate is not present in stub
logging.StringTemplateStyle.validate is not present in stub
logging.config.BaseConfigurator is not present in stub
logging.config.ConvertingDict is not present in stub
logging.config.ConvertingList is not present in stub
logging.config.ConvertingMixin is not present in stub
logging.config.ConvertingTuple is not present in stub
logging.config.DictConfigurator is not present in stub
logging.config.dictConfigClass is not present in stub
logging.config.valid_ident is not present in stub
logging.handlers.QueueListener.handle is not present in stub
logging.handlers.RotatingFileHandler.shouldRollover is not present in stub
logging.handlers.SysLogHandler.append_nul is not present in stub
logging.handlers.TimedRotatingFileHandler.computeRollover is not present in stub
logging.handlers.TimedRotatingFileHandler.getFilesToDelete is not present in stub
logging.handlers.TimedRotatingFileHandler.shouldRollover is not present in stub
logging.handlers.WatchedFileHandler.reopenIfNeeded is not present in stub

@spagh-eddie
Copy link
Contributor Author

spagh-eddie commented Apr 26, 2021

Looks like there are several improvements to be made...

Hiya! Thanks for taking action on this, but I'm a bit confused as to why this is a typeshed issue, can you please help me fix my thoughts? I think:

  • typeshed adds type hints / stubs to standard library
  • type hints help with in/out types of methods like set_name
  • mypy's error "has no attribute" is unrelated to type hints. I think this because another tool pylint gives no error:
$ pylint example.py --disable=missing-module-docstring

--------------------------------------------------------------------
Your code has been rated at 10.00/10 (previous run: 10.00/10, +0.00)

@hauntsaninja
Copy link
Collaborator

hauntsaninja commented Apr 26, 2021

Stubs also define existence. mypy doesn't look at actual code at all when there are stubs (nor would that be possible for C extensions).
I'm not familiar enough with pylint to know why it does what it does (Does it complain if you access logging.Handler.asdfjhaskjdfhaks? Does it import stdlib modules and dynamically introspect them?).

@spagh-eddie
Copy link
Contributor Author

mypy doesn't look at actual code at all when there are stubs

Ah, you have cleared my confusion! I might have a stab at this myself if I have free time over the next week.

I'm not familiar enough with pylint...

$ echo "h.nonexistant()" >> example.py
$ pylint example --disable=missing-module-docstring
************* Module example
example:5:0: E1101: Instance of 'FileHandler' has no 'nonexistant' member (no-member)

---------------------------------------------------------------------
Your code has been rated at -2.50/10 (previous run: 10.00/10, -12.50)

@wiseaidev
Copy link
Contributor

Let's see what do we have here. Looks interesting!

@Akuli
Copy link
Collaborator

Akuli commented May 12, 2021

fixed in #5388

@Akuli Akuli closed this as completed May 12, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants