Skip to content
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

Added AnyLogger type (Logger | LoggerAdapter type) #126057

Closed

Conversation

Avihais12344
Copy link

According to the docs, LoggerAdapter should look mostly like Logger. So it would be really nice to have a type that can be used for both Logger and LoggerAdapter.

Instead of this:

def my_func(logger: Logger | LoggerAdapter):
    ...

I would have this:

def my_func(logger: AnyLogger):
    ...

This is my first PR in the python community, please help me learn if I made a mistake :)

Copy link

cpython-cla-bot bot commented Oct 27, 2024

All commit authors signed the Contributor License Agreement.
CLA signed

@bedevere-app
Copy link

bedevere-app bot commented Oct 27, 2024

Most changes to Python require a NEWS entry. Add one using the blurb_it web app or the blurb command-line tool.

If this change has little impact on Python users, wait for a maintainer to apply the skip news label instead.

@ZeroIntensity
Copy link
Member

Hi, thanks for contributing!

Unfortunately, I don't think this will make it in. We don't really put type aliases into stdlib modules--that should go into typing. But, I don't think typing accepts changes like this, so it's probably a lost cause. I'm not exactly sure where to propose aliases, so I'm going to recommend bringing this up on DPO for now.

If you're interested in contributing to static typing further, you can check out the topic-typing label or typeshed. Thanks!

cc @JelleZijlstra for input on where to propose common aliases, if we even accept those somewhere.

@JelleZijlstra
Copy link
Member

I actually don't see a reason against putting type aliases in standard library modules. We haven't done it before, but the logging module is the natural place to add a type alias that is useful for working with logging.

The typing module should ideally mostly contain typing primitives, objects that form the basis of the type system. We've deprecated most objects in the module that aren't primitives, and I'd prefer not to add new ones.

If you're interested in pushing this forward, here's a few suggestions:

In either case, it would be helpful to give some evidence that this type alias is indeed commonly useful. For example, that could include examples indicating that a lot of users who write typed code using the logging module end up frequently writing Logger | LoggerAdapter.

@Avihais12344
Copy link
Author

@JelleZijlstra Opened an issue about the problem here.

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

Successfully merging this pull request may close these issues.

3 participants