Skip to content

Should a nil :ns-prefix be allowed in codegen/write-namespace!? #211

@harishcm

Description

@harishcm

Hi,

I was using codegen/write-namespace! and found that using a nil :ns-prefix results in a generated namespace that starts with a .. This makes the generated namespace an illegal Java class name.

I was wondering if a nil :ns-prefix would be an allowed? This would allow the same namespace patterns between Clojure and Python, making interop seem more "seamless".

A possible implementation would be the ns-symbol binding in codegen/write-namespace! ignoring a nil or blank :ns-prefix, e.g.,

(defn write-namespace! 
  ...
  (let [...
-       ns-symbol (or ns-symbol (symbol (str ns-prefix "." py-mod-or-cls)))]
+       ns-symbol (or ns-symbol (symbol (str (when-not (s/blank? ns-prefix) (str ns-prefix "."))
+                                            py-mod-or-cls)))]

I see that we can already define :ns-symbol directly to achieve a nil :ns-prefix, so this may already be allowed behaviour.

For your kind consideration.

Many thanks for this excellent library!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions