Skip to content

"FileHandler" has no attribute "set_name" #5257

Closed

Description

@spagh-eddie

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.

Activity

  1. transferred this issue frompython/mypyon Apr 26, 2021
  2. hauntsaninja commented on Apr 26, 2021

    @hauntsaninja
    Collaborator

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

    Details
    λ 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
    
  3. spagh-eddie commented on Apr 26, 2021

    @spagh-eddie
    ContributorAuthor

    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)
  4. hauntsaninja commented on Apr 26, 2021

    @hauntsaninja
    Collaborator

    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?).

  5. spagh-eddie commented on Apr 27, 2021

    @spagh-eddie
    ContributorAuthor

    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)
  6. wiseaidev commented on May 8, 2021

    @wiseaidev
    Contributor

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

  7. Akuli commented on May 12, 2021

    @Akuli
    Collaborator

    fixed in #5388

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions