TypeError: unsupported types for __lshift__: 'tuple', 'int'

Discussion about programs, libraries and tools that work with MicroPython. Mostly these are provided by a third party.
Target audience: All users and developers of MicroPython.
Post Reply
Posts: 118
Joined: Wed Dec 27, 2017 8:52 am

TypeError: unsupported types for __lshift__: 'tuple', 'int'

Post by nikhiledutech » Fri Apr 27, 2018 8:31 am

Hello, i am facing problem of " TypeError: unsupported types for __lshift__: 'tuple', 'int' "

Code: Select all


# Read from device
def I2C_ReadRegister(Rd_Addr):  
	I2C_Rx_Buf = bytearray(2)

	if(i2c.readfrom_mem_into(BME280_I2C_ADDRESS1, Rd_Addr, I2C_Rx_Buf) == None):

#return  Config register value
def BME280_GetConfig():
 	return I2C_ReadRegister(BME280_CONFIG_REG)

def BME280_SetStandbyTime(Value):
	cfgv = 0

	cfgv = BME280_GetConfig()
	cfgv &= ~BME280_CONFIG_REG_TSB__MSK
[b]	cfgv |= Value << BME280_CONFIG_REG_TSB__POS[/b]

BME280_SetStandbyTime(BME280_STANDBY_TIME_1_MS)                   #Standby time 1ms

So can anyone help me to solve this Type Error Issue .

Posts: 230
Joined: Tue Aug 09, 2016 10:58 am

Re: TypeError: unsupported types for __lshift__: 'tuple', 'int'

Post by cefn » Sun May 06, 2018 8:55 am

Hi @nikhiledutech

It's not surprising your posting has taken more than a week for anyone to reply.

Here is a code sample which recreates your issue...

Code: Select all

>>> calculated = (3,4,5) << 4
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: unsupported types for __lshift__: 'tuple', 'int'
It's intriguing how your code could ever create a tuple in the position of Value at the line you highlighted. Perhaps that is what you are drawing our attention to. If that's the case, you have to INVEST TIME in reporting a bug, so that people don't assume you are just refusing to read the Python documentation...

https://docs.python.org/3/library/excep ... #TypeError

Your minimal forum posting with no detail (contra the advice at https://www.chiark.greenend.org.uk/~sgtatham/bugs.html) suggests that you can't be bothered to take the time to investigate bugs for yourself, and want others to do the work, which makes people very much less enthusiastic to respond.

Please reinvest time in investigating the bug for yourself. If Value is somehow becoming magically a tuple from an int value then I'm sure people would be interested to know, but I doubt it very much. If this is the case, you should be able to create a code fragment which demonstrates the problem. Make it clear and share with us what Value actually evaluates to (which is step 1 in any programmer responding to this bug). Probably if you invest the time in reporting, you will fix it yourself because of what you discover on the way.

Worth noting that any stray comma in code (not present in the code sample you shared), would create a tuple. So for example, this also recreates your bug and can be quite a subtle and hard-to-spot error in some cases...

Code: Select all

valueA = 0,
valueB = 1
valueC = valueA << valueB
If this was the source of your error, then I'm sorry to say that the code you posted isn't the code you ran to create the error.

Good luck.

Post Reply