Giter Club home page Giter Club logo

Comments (8)

TomGeorge1234 avatar TomGeorge1234 commented on August 21, 2024

Interesting. I see the problem. i could rename the module but I'd rather not. Seems worth fixing but I don't know the most standard way to fix this. Anyone?

from ratinabox.

pierreglaser avatar pierreglaser commented on August 21, 2024

Workaround:

>>> import importlib
>>> importlib.import_module("ratinabox.Neurons")
<module 'ratinabox.Neurons' from '/Users/pierreglaser/.local/miniforge/envs/ratinabox/lib/python3.9/site-packages/ratinabox/Neurons.py'>

To avoid having to use importlib, consider removing star-imports from __init__.py.

from ratinabox.

TomGeorge1234 avatar TomGeorge1234 commented on August 21, 2024

thanks @pierreglaser.

It's coming back to me now, I added star-imports because I briefly wanted things like

from ratinabox import *
Env = Environment()

but I never adopted this import style and don't think anyone else has either. I just removed them in latest push.

from ratinabox.

colleenjg avatar colleenjg commented on August 21, 2024

Thanks @pierreglaser for the workaround. I'll test it out.

Quick note: @TomGeorge1234, removing the * imports is likely to cause a big impact on everyone's repos, as it should break all imports of any Agent, Env or Neuron classes. Just want to check that that is the intention.

Clarification: I omitted to clarify that although the * imports cause the problem described above in the dev branch, in the v2_beta branch, from ratinabox.env.Environment import Environment in ratinabox/env/__init__.py, for example, has the same effect. It overwrites the module with the class, in the attributes of ratinabox.env.

I see a lot of packages that use this type of import in the inits to make imports less deep - I do think that's fine. Where it fails is where the class and file names also match exactly. The most standard fix is probably to rename the modules to lowercase, as mentioned above. This would also align the package with PEP 8 guidelines, where modules have short, all-lowercase names, with underscores if needed, and classes are named in CapWords, as you've done.

Is there a particular reason you don't want to rename the modules? Unless I've overlooked something, changing their names shouldn't break the code for most users, given that the current import convention has been overwriting the modules in the namespace anyway.

from ratinabox.

colleenjg avatar colleenjg commented on August 21, 2024

Clarification: The removal of the star imports will break current users' imports if they were using import ratinabox, but not if they were using, like you were, from ratinabox.Environment import Environment.

from ratinabox.

colleenjg avatar colleenjg commented on August 21, 2024

So, to be fair, the change of the module names would break imports for people who have been using from ratinabox.Environment import Environment. Which is why, if this name convention change were adopted, I do think it would be best as part of the overall refactor.

from ratinabox.

TomGeorge1234 avatar TomGeorge1234 commented on August 21, 2024

Re quick note
Yeah, it shouldn't break if people do

import ratinabox
from ratinabox.Environment import Environment
from ratinabox.Agent import Agent
from ratinabox.Neurons import PlaceCells, GridCells #...

which I assume is essentially everyone. But if you're okay with the workaround I'll put back the star import (just to be safe) and add it to the refactor down the line.

Re clarification
Yeh so I definitely can't change the module names in RiaB1.x. For 2.0 I agree and will rename Environment.py ---> environment.py, PlaceCells.py ---> placecells.py etc. which should fix this issues and align with PEP8. Thanks for the heads up!

from ratinabox.

colleenjg avatar colleenjg commented on August 21, 2024

That's right - removing the star import would only break imports if they were doing from ratinabox import Environment, Agent, Neurons. I think since no one else appears to have encountered the issue I reported here, I agree - I think it's fine to keep the star import for now, and address this in the refactor!

from ratinabox.

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.