Skip to content

Add some missing logging features #5388

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

Merged
merged 7 commits into from
May 11, 2021
Merged

Add some missing logging features #5388

merged 7 commits into from
May 11, 2021

Conversation

spagh-eddie
Copy link
Contributor

@spagh-eddie spagh-eddie commented May 9, 2021

This handles #5257, #5015, and changes two type to Type[...] for #343


Note I annotated validation_pattern, IDENTIFIER, and extMatch as Any since I cannot do this, which would make a variable, not a type alias.

if sys.version_info >= (3, 7):
    import re
    _Pattern = re.Pattern
else:
    import regex
    _Pattern = regex.Regex
IDENTIFIER: _Pattern

Please note that SMTPHandler.password is not always created depending on what is passed in! But since I know of no workarounds for maybe-exsiting-attributes and the documents suggest:

we usually prefer false negatives (no errors for wrong code) over false positives (type errors for correct code)

I have added it password: str.


I am not fixing everything I see in this PR, I have left a lot of logging.config as-is

$ stubtest logging --custom-typeshed-dir . --concise
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

@github-actions

This comment has been minimized.

1 similar comment
@github-actions

This comment has been minimized.

@spagh-eddie spagh-eddie marked this pull request as draft May 10, 2021 01:21
@github-actions
Copy link
Contributor

According to mypy_primer, this change has no effect on the checked open source code. 🤖🎉

@spagh-eddie spagh-eddie marked this pull request as ready for review May 10, 2021 02:04
Copy link
Collaborator

@srittau srittau left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you, that's very thorough! A few minor notes below about the things you mentioned.

def usesTime(self) -> bool: ... # undocumented

class BufferingFormatter:
linefmt: Formatter
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think line format could be a string like: '%(something)s %(something)s'. So, linefmt should be changed to:

    linefmt: Union[str, Formatter]

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Technically it can be anything with a .format() method, even a string. But that .format() method will be called with only one argument, a log record object. It is possible to create a string that formats them in a useful way, such as "{0.name}: {0.msg}", although that doesn't seem to be how it's intended to be used.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup!

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So the correct fix would be a protocol? We could leave as Any for the moment, though.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Honestly I would just use Formatter. It's what the author of the code intended. (This is old code, likely written before str.format was a thing)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was under the same impression as @Akuli, intended to be a Formatter


class BufferingFormatter:
linefmt: Formatter
def __init__(self, linefmt: Optional[Formatter] = ...) -> None: ...
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here:

    def __init__(self, linefmt: Optional[Union[str, Formatter]] = ...) -> None: ...

Copy link
Collaborator

@srittau srittau left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If someone want to change Formatter to a protocol, they can do it in a separate PR. I'm fine with it being a concrete class for now.

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

Successfully merging this pull request may close these issues.

4 participants