Skip to content

Missing conversion from StringLiteral to unicode_type #6907

Closed

Description

@stuartarchibald

Reporting a bug

  • I have tried using the latest released version of Numba (most recent is
    visible in the change log (https://github.com/numba/numba/blob/master/CHANGE_LOG).
  • I have included a self contained code sample to reproduce the problem.
    i.e. it's possible to run as 'python bug.py'.

This:

from numba import typeof, types
from numba.core.typing import Context

x = types.literal('string literal')
print(x, type(x))
print("conversion:", x.can_convert_to(Context(), types.unicode_type))

does this:

Literal[str](string literal) <class 'numba.core.types.misc.StringLiteral'>
conversion: None

I think it should be possible to convert a StringLiteral to a unicode_type but not the converse.

A can_convert_to() method needs adding to this class:

class StringLiteral(Literal, Dummy):
pass

xref: https://numba.discourse.group/t/how-to-pass-string-argument-to-numba-njit-python-function-from-inside-another-whilst-specifying-signature-type/663 which hits this bug.

Activity

  1. gmarkall commented on Apr 8, 2021

    @gmarkall
    Member

    Would fixing this also fix #6897?

  2. added a commit that references this issue on Apr 12, 2021
    0ae7d9a
  3. added a commit that references this issue on May 28, 2021
    638ed0d
  4. added a commit that references this issue on Aug 11, 2021
    cf78441
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions