Coder Social home page Coder Social logo

Comments (8)

public avatar public commented on July 30, 2024 1

Currently there are a handful of _private stdlib modules in the list. Maybe that's the real bug? :)

https://github.com/PyCQA/flake8-import-order/blob/master/flake8_import_order/stdlib_list.py#L42-L44

Except it's not documented on docs.python.org so it's not something this plugin should recognize

Originally there were no internal _ modules in the stdlib list but they seem to have got added over the many years since.

from flake8-import-order.

sigmavirus24 avatar sigmavirus24 commented on July 30, 2024

_csv would be a private module that you're not intended to import directly. Instead, I expect that csv uses it under the covers and what you get from csv is derived from _csv. I'd argue this is doing the right thing by flagging inappropriate usage of that module (even if it's not obvious)

from flake8-import-order.

sanyassh avatar sanyassh commented on July 30, 2024

I have to import _csv to make annotations like def write(writer: csv_writer) -> None:. I haven't found anything appropriate for annotations like this in usual csv module. Anyway, this is still an issue of flake8 not to recognize _csv correctly.

from flake8-import-order.

sigmavirus24 avatar sigmavirus24 commented on July 30, 2024

I haven't found anything appropriate for annotations like this in usual csv module.

That's disappointing and surprising. I'm not sure that means you should be using _csv.

Anyway, this is still an issue of flake8 not to recognize _csv correctly.

Except it's not documented on docs.python.org so it's not something this plugin should recognize. There's nothing to stop this module from being rewritten in a memory safe language that eliminates _csv and then we're stuck attempting to recognize something that isn't present any longer.

from flake8-import-order.

sanyassh avatar sanyassh commented on July 30, 2024

So you're saying that recognizing _csv and other such modules like_collections, _decimal, _json, _random and so on as Third Party is correct behavior? At least they should be identified as StdlibC, for example. They're not third party modules in any sense.

I haven't found anything appropriate for annotations like this in usual csv module.

That's disappointing and surprising. I'm not sure that means you should be using _csv.

It's a known issue of csv module not exposing the class of csv.writer() result. This SO answer suggests to use _csv._writer: https://stackoverflow.com/a/51270295/9609843

from flake8-import-order.

sigmavirus24 avatar sigmavirus24 commented on July 30, 2024

So you're saying that recognizing _csv and other such modules like_collections, _decimal, _json, _random and so on as Third Party is correct behavior? At least they should be identified as StdlibC, for example. They're not third party modules in any sense.

I'm saying they're not documented as the standard library. They're implementation details. Referring to them is an anti-pattern.

It's a known issue of csv module not exposing the class of csv.writer() result. This SO answer suggests to use _csv._writer: https://stackoverflow.com/a/51270295/9609843

That's probably one of many potential solutions here. But I recognize the rest aren't on StackOverflow so they're not immediately obvious. I'd argue that https://stackoverflow.com/a/51267141 is the better solution since it seems unlikely for mypy to be able to handle other CSV readers/writers that could satisfy the API.

I'd also argue this is more of a bug for typeshed/the stdlib for not providing something here.

from flake8-import-order.

sigmavirus24 avatar sigmavirus24 commented on July 30, 2024

@public that's something I would agree would be a bug. I know y'all aren't really working very much on this these days, but I think a compromise would be to allow people to "extend" what the canonical list of standard library modules is with a flag to Flake8. I'm happy to help out here although I can't commit to a specific timeframe of when that would get a PR or anything.

from flake8-import-order.

jvanasco avatar jvanasco commented on July 30, 2024

The same thing applies to _socket, which is the cPython c extension of socket.

Referring to them is an anti-pattern.

Utilizing them directly may be an anti-pattern, but referring to them is definitely not and required by various use-cases.

In my particular use-case, I must inspect the socket on the raw requests response's _connection or fp and ensure it's class inheritance from socket to extract the remote peer's ip. Under cpython, because of the implementation details, this will never be an instance of socket.socket, and will almost never be an instance of socket._socketobject, but would typically by an instance of _socket._socket. This ultimately traces back to urllib3, and this 5 year old thread I started there: urllib3/urllib3#1071

from flake8-import-order.

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.