question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Can't import Representation class twice (from different packages/telescopes)

See original GitHub issue

I try to import two functions from two packages of two telescopes (CTA / FACT). Both define a PlanarRepresentation class internally.

Error:

    438         if repr_name in REPRESENTATION_CLASSES:
    439             raise ValueError("Representation class {0} already defined"
--> 440                              .format(repr_name))
    441 
    442         REPRESENTATION_CLASSES[repr_name] = cls

ValueError: Representation class planar already defined

MWE without the packages, but same Error, basically just redefining the Representation class:

from astropy.coordinates import BaseRepresentation

class PlanarRepresentation(BaseRepresentation): 
     attr_classes = ['a', 'b'] 
     def __init__(self, x, y, copy=True, **kwargs): 
         pass

class PlanarRepresentation(BaseRepresentation): 
     attr_classes = ['a', 'b'] 
     def __init__(self, x, y, copy=True, **kwargs): 
         pass

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:28 (23 by maintainers)

github_iconTop GitHub Comments

1reaction
mhvkcommented, Apr 15, 2019

The use case is arguably mostly laziness: if you want to initialize or convert, you don’t have to import the relevant class, but just give its name.

So, indeed, changing the name of your class would resolve it, though I think that longer term it still seems reasonable to move the class up to astropy.

1reaction
mhvkcommented, Apr 9, 2019

Could you explain why or when this would be useful?

Well, it certainly is not something we can change any more; it is even in the Getting Started section on coordinates; http://docs.astropy.org/en/latest/coordinates/index.html#representation

Read more comments on GitHub >

github_iconTop Results From Across the Web

Same class name in different packages - java - Stack Overflow
Yes, you can have two classes with the same name in multiple packages. However, you can't import both classes in the same file...
Read more >
Can I import same package twice? Will JVM load the package ...
Yes, you can import a class twice in Java, it doesn't create any issues but, irrespective of the number of times you import,...
Read more >
Modern IDEs are magic. Why are so many coders still using ...
Vim is more than an editor, vim is a language and a tool to translate intent into code. I can 2p to paste...
Read more >
Can python distinguish two different functions defined ... - Quora
You have two workaround options: assigning a different name on import: from foo import bar as foobar; importing the foo and baz modules,...
Read more >
Simulation Curriculum • Support • FAQ • SkySafari for Android
SkySafari for Android Frequently Asked Questions. This page contains answers to the most frequently asked questions about SkySafari for Android.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found