Git Product home page Git Product logo

Comments (9)

sohang3112 avatar sohang3112 commented on June 14, 2024 1

@miguelgrinberg As I commented in the PR, I have already removed the private classes and attributes.

from flask-socketio.

miguelgrinberg avatar miguelgrinberg commented on June 14, 2024

Feel free to contribute type hints for this package to typeshed. I don't discard that at some point in the future when Python typing is mature enough I will do this myself, but I have too many open source packages and I cannot take on the burden of maintaining type hints for all of them given the effort it currently entails.

from flask-socketio.

sohang3112 avatar sohang3112 commented on June 14, 2024

@miguelgrinberg I created this pull request in typeshed repository to add type stubs for Flask-SocketIO. Could you please have a look at it and let me know if I have written the wrong type anywhere?

from flask-socketio.

miguelgrinberg avatar miguelgrinberg commented on June 14, 2024

I did a very quick review and wrote down some comments. In addition, I personally do not agree with adding types for private classes, attributes and methods, since people shouldn't use them and they are also much more likely to change since I have no obligation to preserve them. But of course, it is your project, so do as you wish. :)

from flask-socketio.

sohang3112 avatar sohang3112 commented on June 14, 2024

I personally do not agree with adding types for private classes, attributes and methods

I don't think I type hinted any private attributes or methods (please correct me if I did). I did type hint private classes, since the classes were the type of some public arguments. I'm not sure how else to type hint these public arguments.

For example, I type hinted _SocketIOMiddleware because it's the type of this public attribute: sockio_mw: _SocketIOMiddleware | None

from flask-socketio.

miguelgrinberg avatar miguelgrinberg commented on June 14, 2024

sockio_mw is not a documented attribute. In fact, none of the attributes of class SocketIO are documented, only the methods are. I don't have an obligation to maintain compatibility for undocumented elements, and for that reason nobody should use them unless they are willing to assume a risk. My opinion is that those should not be exposed in type hints. Check my documentation, anything that is not there should be considered private.

from flask-socketio.

miguelgrinberg avatar miguelgrinberg commented on June 14, 2024

Another thing to consider is that you are using the | character liberally in your type hints. If I remember correctly this syntax is only valid for Python 3.10+, but this package supports older Python releases. So maybe it makes more sense to use the more verbose Union and Optional type hints.

from flask-socketio.

sohang3112 avatar sohang3112 commented on June 14, 2024

Another thing to consider is that you are using the | character liberally in your type hints. If I remember correctly this syntax is only valid for Python 3.10+, but this package supports older Python releases. So maybe it makes more sense to use the more verbose Union and Optional type hints.

@miguelgrinberg Actually the type stubs won't be read by the Python interpreter directly, but rather by static analyzers like mypy, so it's safe to use the latest syntax.

from flask-socketio.

miguelgrinberg avatar miguelgrinberg commented on June 14, 2024

You don't seem to understand what I'm saying. If you add types for private elements of the library, users will be more likely to incorporate them in their programs. And these programs will later break when I need to change those internals, which I often do.

from flask-socketio.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.